package com.sam.spring.chapter3;

import junit.framework.Assert;

import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.UrlResource;

public class ResourceLoaderTest {
	@Test
	public void testResourceLoad() {
		ResourceLoader loader = new DefaultResourceLoader();
		Resource resource = loader
				.getResource("classpath:com/sam/spring/chapter3/test1.txt");
		System.out.println(resource.getClass());
		// 验证返回的是ClassPathResource
		Assert.assertEquals(ClassPathResource.class, resource.getClass());

		Resource resource2 = loader
				.getResource("file:com/sam/spring/chapter3/test1.txt");
		System.out.println(resource2.getClass());
		// 验证返回的是ClassPathResource
		Assert.assertEquals(UrlResource.class, resource2.getClass());

		Resource resource3 = loader
				.getResource("com/sam/spring/chapter3/test1.txt");
		System.out.println(resource3.getClass());
		// 验证返默认可以加载ClasspathResource
		Assert.assertTrue(resource3 instanceof ClassPathResource);
	}
}
